/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


package beatbox;
import java.lang.Math;
import javafx.animation.*;
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.RadialGradient;
import javafx.scene.effect.*;
import javafx.scene.effect.light.*;
import javafx.scene.input.MouseEvent;

/**
 *A box representing a single recorded sample
 * @author Kyle
 */

public class SampleBox extends CustomNode {

    public var outline = false; //if it should be a placeholder-looking box
    public var boxSize: Integer = 15;
    public var selected = false;  //if the node is currently selected, displays
                            //differently
    public var exampleId: Integer; //the id of this example (given by chuck)
    var red = 0;
    var fade = Timeline {
        repeatCount: 1;
        keyFrames: [
        KeyFrame {time: 0s values: red => 0},
        KeyFrame {time: 5s values: red => 255 tween Interpolator.EASEOUT}]
    };

    override var onMouseEntered = function(me:MouseEvent) {
        ChuckBoard.playExample(exampleId);
    }

    

    override public function create(): Node {
        fade.playFromStart();
        var strokeDashArray: Number[];
        var fill: Paint;
        if (outline) {
            Rectangle {
                arcWidth: boxSize / 3;
                arcHeight: boxSize / 3;
                width: boxSize
                height: boxSize
                fill: Color.TRANSPARENT
                stroke: bind if (selected) then Color.BLACK else Color.BLACK;
                strokeDashArray: bind if (outline) then [4,4] else [];
            }
       } else {
            Rectangle {
                arcWidth: boxSize / 3;
                arcHeight: boxSize / 3;
                width: boxSize
                height: boxSize
                fill: bind if (selected) then Color.rgb(red, 33, Math.min(255,255+33-red)) else
                    Color.rgb(red, 133, Math.min(255,255+133-red));
                stroke: bind if (selected) then Color.BLACK else Color.BLACK;
                strokeDashArray: bind if (outline) then [4,4] else [];
            }
       }

    }

}